package com.ruoyi.project.remoteControl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.project.remoteControl.domain.DeviceAliveInfo;
import com.ruoyi.project.remoteControl.mapper.DeviceAliveInfoMapper;
import com.ruoyi.project.remoteControl.service.ReceiveAliveMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ReceiveAliveMsgServiceImpl implements ReceiveAliveMsgService {
    @Autowired
    DeviceAliveInfoMapper deviceAliveInfoMapper;
    
    /**
     * 向数据库插入或更新被控端存活信息
     * @param deviceAliveInfo
     */
    @Override
    public void insertOrUpdateRemoteComputerStatus(DeviceAliveInfo deviceAliveInfo) {
        // 使用BaseMapper里的方法
        QueryWrapper<DeviceAliveInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("DEVICE_CLIENT_ID",deviceAliveInfo.getDeviceClientId());
//        queryWrapper.eq("DEVICE_NAME",deviceAliveInfo.getDeviceName());
        if (deviceAliveInfoMapper.selectOne(queryWrapper)==null){
            deviceAliveInfoMapper.insert(deviceAliveInfo);
        } else {
            deviceAliveInfoMapper.update(deviceAliveInfo,queryWrapper);
        }
        
//        使用自定义的mapper方法
//        if (computerInfoMapper.selectOneByDeviceClientId(deviceAliveInfo.getDeviceClientId())==null){
//            computerInfoMapper.insertComputerInfo(deviceAliveInfo);
//        } else {
//            computerInfoMapper.updateComputerInfo(deviceAliveInfo);
//        }
    }
}
